/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package mH1.impl;

import mH1.MH1;
import mH1.MH1Package;

import mS.Scheduler;

import node1.impl.Node1Impl;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.ecore.EClass;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import procUseNB.ProcUseNB;
import procUseNB.impl.ProcUseNBImpl;
import techEDFLL73.TechEDFLL73;
import techEDFLL73.impl.TechEDFLL73Impl;
import techLL73.LL73;
import techLL73.impl.LL73Impl;
import techResponseTimeNB.ResponseTimeRMNB;
import techResponseTimeNB.impl.ResponseTimeRMNBImpl;
import utils.UtilsEDF;
import utils.UtilsModelInstance;
import boundRMLL73.BoundRMLL73;
import boundRMLL73.impl.BoundRMLL73Impl;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>MH1</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link mH1.impl.MH1Impl#getScheduler <em>Scheduler</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class MH1Impl extends Node1Impl implements MH1 {
	/**
	 * The default value of the '{@link #getScheduler() <em>Scheduler</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getScheduler()
	 * @generated
	 * @ordered
	 */
	protected static final Scheduler SCHEDULER_EDEFAULT = Scheduler.FP;

	/**
	 * The cached value of the '{@link #getScheduler() <em>Scheduler</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getScheduler()
	 * @generated
	 * @ordered
	 */
	protected Scheduler scheduler = SCHEDULER_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected MH1Impl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return MH1Package.Literals.MH1;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Scheduler getScheduler() {
		return scheduler;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setScheduler(Scheduler newScheduler) {
		Scheduler oldScheduler = scheduler;
		scheduler = newScheduler == null ? SCHEDULER_EDEFAULT : newScheduler;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MH1Package.MH1__SCHEDULER, oldScheduler, scheduler));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MH1Package.MH1__SCHEDULER:
				return getScheduler();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MH1Package.MH1__SCHEDULER:
				setScheduler((Scheduler)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MH1Package.MH1__SCHEDULER:
				setScheduler(SCHEDULER_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MH1Package.MH1__SCHEDULER:
				return scheduler != SCHEDULER_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (scheduler: ");
		result.append(scheduler);
		result.append(')');
		return result.toString();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public void compute() {
		/* RM Case -> 0*/
		if (this.scheduler == Scheduler.FP || this.scheduler == Scheduler.RM) {
			
			/* ================================================= technicRMLL73 ================================================== */
			/* Create instance of technicRMLL73, add to general List, children list and compute */
			LL73 t_rm = (LL73)UtilsModelInstance.lookForComputeBox(this, LL73Impl.class);
			
			/**/
			if (t_rm == null) {
				
				t_rm = UtilsModelInstance.createTechRMLL73(null, null);
				UtilsModelInstance.linkComputeBox(this, t_rm, false);
			}
			/**/
			else {
				UtilsModelInstance.linkComputeBox(this, t_rm, true);
			}
			t_rm.compute();

			/* ================================================= ResponseTimeRMNB ================================================== */
			/* Create instance of ResponseTimeRMNB, add to general List, children list and compute */
			ResponseTimeRMNB rt_rmnb = (ResponseTimeRMNB)UtilsModelInstance.lookForComputeBox(this, ResponseTimeRMNBImpl.class);
			
			/**/
			if (rt_rmnb == null) {
				
				rt_rmnb = UtilsModelInstance.createResponseTimeRMNB(this.tasks);
				UtilsModelInstance.linkComputeBox(this, rt_rmnb, false);
			}
			/**/
			else {
				UtilsModelInstance.linkComputeBox(this, rt_rmnb, true);
			}
			rt_rmnb.compute();
			
			/* ================================================= BoundRMLL73 ================================================== */
			/* Create instance of BoundRMLL73, add to general List, children list and compute */
			BoundRMLL73 b_rm = (BoundRMLL73)UtilsModelInstance.lookForComputeBox(this, BoundRMLL73Impl.class);
			
			/**/
			if (b_rm == null) {
				
				b_rm = UtilsModelInstance.createBound_RM_LL73(this.tasks.size());
				UtilsModelInstance.linkComputeBox(this, b_rm, false);
			}
			/**/
			else {
				UtilsModelInstance.linkComputeBox(this, b_rm, true);
			}
			b_rm.compute();
			
		
		}
		
		/* EDF Case*/
		else {
			
			/**/
			TechEDFLL73 t_ll73 = (TechEDFLL73)UtilsModelInstance.lookForComputeBox(this, TechEDFLL73Impl.class);
			
			/**/
			if (t_ll73 == null) {
				
				t_ll73 = UtilsEDF.createTechEDFLL73(null);
				UtilsModelInstance.linkComputeBox(this, t_ll73, false);
			}
			else {
				UtilsModelInstance.linkComputeBox(this, t_ll73, true);
			}
			t_ll73.compute();
		}
		
		/* ================================================= ProcessorUtilisationNB ================================================== */
		/* Create instance of ProcessorUtilisationNB, add to general List, children list and compute */
		ProcUseNB pu = (ProcUseNB)UtilsModelInstance.lookForComputeBox(this, ProcUseNBImpl.class);
		
		/**/
		if (pu == null) {
			
			pu = UtilsModelInstance.createPUNB(this.tasks);
			UtilsModelInstance.linkComputeBox(this, pu, false);
		}
		/**/
		else {
			UtilsModelInstance.linkComputeBox(this, pu, true);
		}
		pu.compute();
	}

	
} //MH1Impl
